<?php

namespace dk\widget;
use dk\core\Version;

class Ui extends Base {
    use \dk\traits\Singleton;

    /**
     * @param \weixin\core\View $plug
     */
    function bindHandle($plug) {
        $plug->regPlug("ui", function($params){
            if(!is_array($params)){
                $args = func_get_args();
                $params = ['src' => $args[0]];
            }
            return $this->render($params);
        });
        return $this;
    }

    function render($args = []){
        if($args){
            $this->setRequest($args);
        }
        $src = $this->q('src');
        if(strpos($src, 'http://') !== false){
            return $src;
        } else {
            $src = ltrim($src, '/');
            $src = '/' . $src;
        }
        return  'http://' . $_SERVER['SERVER_NAME'] .  $this->q('src');
    }
}